package models

func GetUserInfo(user UserTwoWeek) (UserTwoWeek, error) {
	var newUser UserTwoWeek
	res := db.Where(user).First(&newUser)
	return newUser, res.Error
}
func CreateUser(user UserTwoWeek) (UserTwoWeek, error) {
	res := db.Create(&user)
	return user, res.Error
}
func GetFriendInfo(friend FriendTwo) (FriendTwo, error) {
	var newFriend FriendTwo
	res := db.Where(friend).First(&newFriend)
	return newFriend, res.Error
}
func CreateFriend(friend FriendTwo) (FriendTwo, error) {
	res := db.Create(&friend)
	return friend, res.Error
}

func GetGroupAll(group GroupTwo) ([]GroupTwo, error) {
	var newGroup []GroupTwo
	res := db.Where(group).Find(&newGroup)
	return newGroup, res.Error
}
func CreateBarrage(barrage Barrage) (Barrage, error) {
	res := db.Create(&barrage)
	return barrage, res.Error
}

// GetBarrage todo: 查询弹幕  （视频ID  剧集ID  弹幕开始截至时间）
func GetBarrage(videoId, dramaSeriesId, startTime, endTime int) ([]Barrage, error) {
	var ss []Barrage
	res := db.Where("video_id = ? AND episodes_id = ?", videoId, dramaSeriesId).Where("sss >= ?", startTime).Where("sss <= ?", endTime).Find(&ss)
	return ss, res.Error
}

// GetTopInfo todo: 根据频道获取MySQL数据
func GetTopInfo(video Video) ([]Video, error) {
	var VideoAll []Video
	res := db.Where(video).Order("attendance desc").Limit(10).Find(&VideoAll)
	return VideoAll, res.Error
}

// CreateAnchor todo: 创建直播间
func CreateAnchor(cast BroadCast) (BroadCast, error) {
	res := db.Create(&cast)
	return cast, res.Error
}
func GetAnchor(cast BroadCast) (BroadCast, error) {
	var newBroadcast BroadCast
	res := db.Where(cast).First(&newBroadcast)
	return newBroadcast, res.Error
}
